package main

import (
	"fmt"
	"net/http"
)

/*
● 把一个满足特定签名的普通函数显式转化为自身类型的实例
● 转换后的实例也是某个单方法接口的实现者
*/
type Handler interface {
	ServeHTTP(http.ResponseWriter, *http.Request)
}

type HandlerFunc func(http.ResponseWriter, *http.Request)

// 实现了 接口
func (f HandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	f(w, r)
}

func greetings(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "Welcome!")
}

func main() {
	http.Handle("/hello", http.HandlerFunc(greetings))
	http.ListenAndServe(":8080", nil)
}
